package com.globallogic.training.javase.university;

import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;

import com.globallogic.training.javase.university.curriculum.Stream;
import com.globallogic.training.javase.university.member.Instructor;
import com.globallogic.training.javase.university.schedule.Auditorium;
import com.globallogic.training.javase.university.schedule.Schedule;

public class Department {

	private String id;

	private String title;

	private Set<Stream> streams;

	private Schedule schedule;

	
	public Department() {
		streams = new HashSet<Stream>();
		schedule = new Schedule();
	}

	public Department(String id, String title) {

		if (StringUtils.isBlank(id)) {
			throw new IllegalArgumentException(
					"Input 'id' parameter should not be null");
		}

		if (StringUtils.isBlank(title)) {
			throw new IllegalArgumentException(
					"Input 'title' parameter should not be null");
		}

		this.id = id;
		this.title = title;

		streams = new HashSet<Stream>();
		schedule = new Schedule();
	}

	public String getId() {
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}
	
	public boolean addStream(Stream stream) {
		return streams.add(stream);
	}
	
	public boolean removeStream(Stream stream) {
		return streams.remove(stream);
	}
	
	public Stream getStream(String id) {
		for (Stream stream : streams) {
			if (stream.getId().equals(id)) {
				return stream;
			}
		}
		
		return null;
	}
	
	public Stream[] listStreams() {
		return streams.toArray(new Stream[streams.size()]);
	}

	public void setSchedule(Schedule schedule) {
		this.schedule = schedule;
	}

	public Schedule getSchedule() {
		return schedule;
	}

	public Schedule getSchedule(Instructor instructor) {
		return null;
	}

	public Schedule getSchedule(Auditorium auditorium) {

		return null;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;

		return result * prime + id.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}

		if (getClass() != obj.getClass()) {
			return false;
		}
		Department other = (Department) obj;
		if (id.equals(other.id)) {
			return true;
		}

		return false;
	}

	@Override
	public String toString() {
		return id;
	}
}
